<template>
  <el-dialog :title="dataForm.name" :close-on-click-modal="false" :visible.sync="visible" class="printtemplate">
    <el-row>
      <el-col :span="10" :gutter="20">
        <el-form :model="dataForm" label-position="top" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px" :inline="true">
          <!-- <el-form-item
            label="打印单据名"
            prop="name"
            disabled
          >
            <el-input
              v-model="dataForm.name"
              placeholder="打印单据名"
            ></el-input>
          </el-form-item> -->
          <el-form-item label="规格" prop="specs">
            <!-- <el-input v-model="dataForm.specs" placeholder="规格"></el-input> -->
            <el-radio-group v-model="dataForm.specs" @change="changeSelect()">
              <el-radio :label="'58mm'" :disabled="btnDisabled">58mm</el-radio>
              <el-radio :label="'80mm'" :disabled="btnDisabled">80mm</el-radio>
              <el-radio :label="'A5'">A5</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注" prop="note" class="note">
            <el-input v-model="dataForm.note" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" placeholder="备注"></el-input>
          </el-form-item>
          <div style="margin: 5px 0;"></div>
          <el-form-item prop="preview">
            <!-- <el-input v-model="dataForm.preview" placeholder="打印前是否预览 0否，1是"></el-input> -->
            <el-checkbox v-model="dataForm.preview">不显示打印预览窗口，直接打印小票</el-checkbox>
          </el-form-item>
          <el-form-item label="默认打印机" prop="defalutPrint" class="w100">
            <!-- <el-input v-model="dataForm.defalutPrint" placeholder="默认打印机"></el-input> -->
            <el-select v-model="dataForm.defaultPrint" placeholder="请选择">
              <el-option v-for="item in printList" :key="item.label" :label="item.label" :value="item.label"></el-option>
            </el-select>
          </el-form-item>
          <div style="margin: 5px 0;"></div>
          <el-form-item label="打印份数" prop="printSum"><el-input v-model="dataForm.printSum" placeholder="打印份数"></el-input></el-form-item>
          <div style="margin: 5px 0;"></div>
          <el-form-item label="打印室内容宽度偏差" prop="printContentOffset">
            <el-input v-model="dataForm.printContentOffset" placeholder="打印室内容宽度偏差"></el-input>
          </el-form-item>
          <el-form-item label="打印时纸张宽度偏差" prop="printPaperOffset"><el-input v-model="dataForm.printPaperOffset" placeholder="打印时纸张宽度偏差"></el-input></el-form-item>
        </el-form>
      </el-col>
      <el-col :span="14">
        <T1 v-if="selected === '58mm' && this.dataForm.name === '登记单'" :note="this.dataForm.note"></T1>
        <T2 v-if="selected === '80mm' && this.dataForm.name === '登记单'" :note="this.dataForm.note"></T2>
        <T3 v-if="selected === 'A5' && this.dataForm.name === '登记单'" :note="this.dataForm.note"></T3>
        <T4 v-if="selected === '58mm' && this.dataForm.name === '结账单'" :note="this.dataForm.note" :finance-data="this.financeData"></T4>
        <T5 v-if="selected === '80mm' && this.dataForm.name === '结账单'" :note="this.dataForm.note" :finance-data="this.financeData"></T5>
        <T6 v-if="selected === 'A5' && this.dataForm.name === '结账单'" :note="this.dataForm.note" :finance-data="this.financeData"></T6>
        <T7 v-if="selected === '58mm' && this.dataForm.name === '收款单'" :note="this.dataForm.note"></T7>
        <T8 v-if="selected === '80mm' && this.dataForm.name === '收款单'" :note="this.dataForm.note"></T8>
        <T9 v-if="selected === 'A5' && this.dataForm.name === '收款单'" :note="this.dataForm.note"></T9>
        <T10 v-if="selected === '58mm' && this.dataForm.name === '退款单'" :note="this.dataForm.note"></T10>
        <T11 v-if="selected === '80mm' && this.dataForm.name === '退款单'" :note="this.dataForm.note"></T11>
        <T12 v-if="selected === 'A5' && this.dataForm.name === '退款单'" :note="this.dataForm.note"></T12>

        <hf58 v-if="selected === '58mm' && this.dataForm.name === '换房单'" :note="this.dataForm.note"></hf58>
        <hf80 v-if="selected === '80mm' && this.dataForm.name === '换房单'" :note="this.dataForm.note"></hf80>
        <hfA5 v-if="selected === 'A5' && this.dataForm.name === '换房单'" :note="this.dataForm.note"></hfA5>

        <xz58 v-if="selected === '58mm' && this.dataForm.name === '续住单'" :note="this.dataForm.note"></xz58>
        <xz80 v-if="selected === '80mm' && this.dataForm.name === '续住单'" :note="this.dataForm.note"></xz80>
        <xzA5 v-if="selected === 'A5' && this.dataForm.name === '续住单'" :note="this.dataForm.note"></xzA5>

        <pay58 v-if="selected === '58mm' && this.dataForm.name === '支付单'"></pay58>
        <pay80 v-if="selected === '80mm' && this.dataForm.name === '支付单'"></pay80>
        <payA5 v-if="selected === 'A5' && this.dataForm.name === '支付单'"></payA5>

        <pos58 v-if="selected === '58mm' && this.dataForm.name === 'POS结账单'" :note="this.dataForm.note"></pos58>
        <pos80 v-if="selected === '80mm' && this.dataForm.name === 'POS结账单'" :note="this.dataForm.note"></pos80>
        <posA5 v-if="selected === 'A5' && this.dataForm.name === 'POS结账单'" :note="this.dataForm.note"></posA5>

        <djrz58 v-if="selected === '58mm' && this.dataForm.name === '入住登记单'" :type="2" :note="this.dataForm.note"></djrz58>
        <djrz80 v-if="selected === '80mm' && this.dataForm.name === '入住登记单'" :type="2" :note="this.dataForm.note"></djrz80>
        <djrzA5 v-if="selected === 'A5' && this.dataForm.name === '入住登记单'" :type="2" :note="this.dataForm.note"></djrzA5>

        <jb58 v-if="selected === '58mm' && this.dataForm.name === '交班表'"
        :dataMap="dataMap"
        :nextDeposit="nextDeposit" :nextMoney="nextMoney" :upperDepositMap="upperDepositMap" :depositMap="depositMap"
        :nextDepositMap="nextDepositMap" :upperMoneyMap="upperMoneyMap" :payDataMap="payDataMap" :nextMoneyMap="nextMoneyMap"
        :user="user" :seller="seller" :isFisrt="'0'" :username="'1'"
        :goodsPrint="false" :goods="shiftWorkGoodsTable" :startTime="'2020-07-13 12:20:30'" :endTime="'2020-07-14 12:20:30'"
        ></jb58>
        <jb80 v-if="selected === '80mm' && this.dataForm.name === '交班表'"
        :dataMap="dataMap"
        :nextDeposit="nextDeposit" :nextMoney="nextMoney" :upperDepositMap="upperDepositMap" :depositMap="depositMap"
        :nextDepositMap="nextDepositMap" :upperMoneyMap="upperMoneyMap" :payDataMap="payDataMap" :nextMoneyMap="nextMoneyMap"
        :user="user" :seller="seller" :isFisrt="'0'" :username="'2'"
        :goodsPrint="false" :goods="shiftWorkGoodsTable" :startTime="'2020-07-13 12:20:30'" :endTime="'2020-07-14 12:20:30'"
        ></jb80>
        <jbA5 v-if="selected === 'A5' && this.dataForm.name === '交班表'"
        :dataMap="dataMap"
        :nextDeposit="nextDeposit" :nextMoney="nextMoney" :upperDepositMap="upperDepositMap" :depositMap="depositMap"
        :nextDepositMap="nextDepositMap" :upperMoneyMap="upperMoneyMap" :payDataMap="payDataMap" :nextMoneyMap="nextMoneyMap"
        :user="user" :seller="seller" :isFisrt="'0'" :username="'3'"
        :goodsPrint="false" :goods="shiftWorkGoodsTable" :startTime="'2020-07-13 12:20:30'" :endTime="'2020-07-14 12:20:30'"
        ></jbA5>
        <jba5-mx v-show="selected === 'A5' && this.dataForm.name === '交班明细表'" ref="jba5_mx"
          :seller="seller" 
          :startTime="'2020-07-13 12:20:30'" :endTime="'2020-07-14 12:20:30'"
          :username="'admin'"
          :dataMap="dataMap"
          :countMap="{'现金': 0, '银行卡': 0}"
          :fyPrint="true"
        />
      </el-col>
    </el-row>

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getLodop } from '../../../../utils/lodop';
import djM58 from '../../../common/printtemplate/dengji_58mm';
import djM80 from '../../../common/printtemplate/dengji_80mm';
import djA5 from '../../../common/printtemplate/dengji_A5';
import jzM58 from '../../../common/printtemplate/jiezhang_58mm';
import jzM80 from '../../../common/printtemplate/jiezhang_80mm';
import jzA5 from '../../../common/printtemplate/jiezhang_A5';
import sk58 from '../../../common/printtemplate/shoukuan_58mm';
import sk80 from '../../../common/printtemplate/shoukuan_80mm';
import skA5 from '../../../common/printtemplate/shoukuan_A5';
import fk58 from '../../../common/printtemplate/fukuan_58mm';
import fk80 from '../../../common/printtemplate/fukuan_80mm';
import fkA5 from '../../../common/printtemplate/fukuan_A5';
import jb58 from '../../../common/printtemplate/jiaoban_58mm';
import jb80 from '../../../common/printtemplate/jiaoban_80mm';
import jbA5 from '../../../common/printtemplate/jiaoban_A5';
import hf58 from '../../../common/printtemplate/huanfang_58mm';
import hf80 from '../../../common/printtemplate/huanfang_80mm';
import hfA5 from '../../../common/printtemplate/huanfang_A5';
import xz58 from '../../../common/printtemplate/xuzhu_58mm';
import xz80 from '../../../common/printtemplate/xuzhu_80mm';
import xzA5 from '../../../common/printtemplate/xuzhu_A5';
import pay58 from '../../../common/printtemplate/pay_58mm';
import pay80 from '../../../common/printtemplate/pay_80mm';
import payA5 from '../../../common/printtemplate/pay_A5';
import djrz58 from '../../../common/printtemplate/dengjiruzhu_58mm';
import djrz80 from '../../../common/printtemplate/dengjiruzhu_80mm';
import djrzA5 from '../../../common/printtemplate/dengjiruzhu_A5';
  import pos58 from '../../../common/printtemplate/pos_58mm';
  import pos80 from '../../../common/printtemplate/pos_80mm';
  import posA5 from '../../../common/printtemplate/pos_A5';

import jba5_mx from '@/views/common/printtemplate/jiaoban_A5_mx'

export default {
  data() {
    return {
      financeData:JSON.parse('[{"id":3313,"sellerId":611,"userId":null,"payType":4,"creatTime":"2020-07-02 11:26:49","payPrice":169,"banks":null,"banksNumber":null,"referenceNumber":null,"termValidity":null,"roomPriceTime":"2020-07-02","peopleId":443,"consumeId":null,"remarks":"2020-07-02房费","consumeInfo":"2020-07-02房费","inpOrderNum":null,"sysOrderNum":null,"collectionNo":null,"refundNo":null,"transferNo":"202007021204360002","nowType":null,"type":0,"turnType":0,"demolitionType":0,"turnPeopleId":0,"state":null,"fukuan":null,"submitType":null,"submitIds":null,"sign":null,"sellerName":null,"consumeName":null,"demolitions":null,"nowTypeName":null,"xiaofeiMoney":null,"fukuanMoney":null},{"id":3314,"sellerId":611,"userId":null,"payType":0,"creatTime":"2020-07-02 11:27:36","payPrice":500,"banks":"","banksNumber":"","referenceNumber":"","termValidity":"","roomPriceTime":null,"peopleId":443,"consumeId":null,"remarks":"","consumeInfo":null,"inpOrderNum":null,"sysOrderNum":null,"collectionNo":null,"refundNo":null,"transferNo":null,"nowType":9,"type":0,"turnType":0,"demolitionType":0,"turnPeopleId":null,"state":null,"fukuan":null,"submitType":null,"submitIds":null,"sign":null,"sellerName":null,"consumeName":null,"demolitions":null,"nowTypeName":"现金","xiaofeiMoney":null,"fukuanMoney":null},{"id":3315,"sellerId":611,"userId":null,"payType":0,"creatTime":"2020-07-02 11:50:38","payPrice":100,"banks":"","banksNumber":"","referenceNumber":"","termValidity":"","roomPriceTime":null,"peopleId":443,"consumeId":null,"remarks":"","consumeInfo":null,"inpOrderNum":null,"sysOrderNum":null,"collectionNo":null,"refundNo":null,"transferNo":null,"nowType":9,"type":0,"turnType":0,"demolitionType":0,"turnPeopleId":null,"state":null,"fukuan":null,"submitType":null,"submitIds":null,"sign":null,"sellerName":null,"consumeName":null,"demolitions":null,"nowTypeName":"现金","xiaofeiMoney":null,"fukuanMoney":null},{"id":3316,"sellerId":611,"userId":null,"payType":0,"creatTime":"2020-07-02 11:50:46","payPrice":100,"banks":"","banksNumber":"","referenceNumber":"","termValidity":"","roomPriceTime":null,"peopleId":443,"consumeId":null,"remarks":"","consumeInfo":null,"inpOrderNum":null,"sysOrderNum":null,"collectionNo":null,"refundNo":null,"transferNo":null,"nowType":9,"type":0,"turnType":0,"demolitionType":0,"turnPeopleId":null,"state":null,"fukuan":null,"submitType":null,"submitIds":null,"sign":null,"sellerName":null,"consumeName":null,"demolitions":null,"nowTypeName":"现金","xiaofeiMoney":null,"fukuanMoney":null}]'),
      visible: false,
      printList: [],
      selected: '',
      dataForm: {
        id: 0,
        name: '',
        specs: '',
        note: '',
        preview: '',
        defaultPrint: '',
        printSum: '',
        printContentOffset: '',
        printPaperOffset: ''
      },
      dataRule: {
        name: [{ required: true, message: '打印单据名不能为空', trigger: 'blur' }],
        specs: [{ required: true, message: '规格不能为空', trigger: 'blur' }],
        note: [{ required: true, message: '备注不能为空', trigger: 'blur' }],
        preview: [{ required: true, message: '打印前是否预览 0否，1是不能为空', trigger: 'blur' }],
        defaultPrint: [{ required: true, message: '默认打印机不能为空', trigger: 'blur' }],
        printSum: [{ required: true, message: '打印份数不能为空', trigger: 'blur' }],
        printContentOffset: [{ required: true, message: '打印室内容宽度偏差不能为空', trigger: 'blur' }],
        printPaperOffset: [{ required: true, message: '打印时纸张宽度偏差不能为空', trigger: 'blur' }]
      },
      dataMap:{},
      payDataMap:{},
      depositMap:{},
      upperMoneyMap:{},
      upperDepositMap:{},
      nextMoneyMap:{},
      nextDepositMap:{},
      nextMoney:{},
      nextDeposit:{},
              user:{},
    seller:{},
    
      btnDisabled: false
    };
  },
  components: {
    T1: djM58,
    T2: djM80,
    T3: djA5,
    T4: jzM58,
    T5: jzM80,
    T6: jzA5,
    T7: sk58,
    T8: sk80,
    T9: skA5,
    T10: fk58,
    T11: fk80,
    T12: fkA5,
    jb58,
    jb80,
    jbA5,
    hf58,
    hf80,
    hfA5,
    xz58,
    xz80,
    xzA5,
    pay58,
    pay80,
    payA5,
    djrz58,
    djrz80,
    djrzA5,
    pos58,
    pos80,
    posA5,

    'jba5-mx': jba5_mx
  },
  watch: {
    'dataForm.name'(newVal) {
      if (newVal && newVal === '交班明细表') {
        this.btnDisabled = true

        this.$refs.jba5_mx.yulan()
      } else {
        this.btnDisabled = false
      }
    }
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields();
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/hotel/thotelprinttemplate/info/${this.dataForm.id}`),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.name = data.tHotelPrintTemplate.name;
              this.dataForm.specs = data.tHotelPrintTemplate.specs;
              this.dataForm.note = data.tHotelPrintTemplate.note;
              this.dataForm.preview = data.tHotelPrintTemplate.preview;
              this.dataForm.defaultPrint = data.tHotelPrintTemplate.defaultPrint;
              this.dataForm.printSum = data.tHotelPrintTemplate.printSum;
              this.dataForm.printContentOffset = data.tHotelPrintTemplate.printContentOffset;
              this.dataForm.printPaperOffset = data.tHotelPrintTemplate.printPaperOffset;
              this.getPrintList();
              this.changeSelect();
              this.getData();
              this.getUser()
            }
          });
        }
      });
    },
    getUser(){

        this.$http({
        url: this.$http.adornUrl('/hotel/thotelprinttemplate/printInfo'),
        method: 'get',
        }).then(({ data }) => {
        if (data && data.code === 0) {
			console.log(data)
		  this.user=data.user
		  this.seller=data.seller
        } else {

        }
		})
	},
    /**
     * 交班信息
     */

    getData(){
        this.$http({
        url: this.$http.adornUrl('/hotel/thotelshiftwork/getShiftWorkData'),
        method: 'get',
        params: this.$http.adornParams({
            startTime:this.startTime,
            endTime:this.endTime,
        })
        }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataMap=data.data
          this.payDataMap=data.payData
          this.depositMap=data.deposit
            this.isFirst=data.isFirst
            this.upperMoneyMap=data.upperMoneyMap
          this.upperDepositMap=data.upperDepositMap
          this.nextMoneyMap=data.nextMoneyMap
          this.nextDepositMap=data.nextDepositMap
          this.nextMoney=data.nextMoney
          this.nextDeposit=data.nextDeposit




        } else {

        }
         })
      },
    // 表单提交
    dataFormSubmit() {
      console.log(this.dataForm.defalutPrint);
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(`/hotel/thotelprinttemplate/${!this.dataForm.id ? 'save' : 'update'}`),
            method: 'post',
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              name: this.dataForm.name,
              specs: this.dataForm.specs,
              note: this.dataForm.note,
              preview: this.dataForm.preview,
              defaultPrint: this.dataForm.defaultPrint,
              printSum: this.dataForm.printSum,
              printContentOffset: this.dataForm.printContentOffset,
              printPaperOffset: this.dataForm.printPaperOffset
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit('refreshDataList');
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    },
    getPrintList() {
      let LODOP = getLodop();
      if (!LODOP) {
        this.$alert(
          `<br><font color='#FF00FF'>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href='http://www.lodop.net/download/CLodop_Setup_for_Win32NT_4.088Extend.zip' download target='_self'>执行安装</a>,安装后请刷新页面。</font>`,
          '安装',
          {
            confirmButtonText: '确定',
            dangerouslyUseHTMLString: true
          }
        );
        return;
      }
      // 获取打印机个数
      let count = LODOP.GET_PRINTER_COUNT();
      let printValue = LODOP.GET_PRINTER_NAME(-1); //获取默认打印机
      this.printList = Array(count)
        .fill(null)
        .map((...args) => {
          if (printValue === LODOP.GET_PRINTER_NAME(args[1])) {
            this.dataForm.defalutPrint = args[1];
          }
          return {
            value: args[1], // args[1]为数组索引
            label: LODOP.GET_PRINTER_NAME(args[1]) // 获取打印机名称
          };
        });
      console.log(this.printList);
    },
    changeSelect() {
      this.selected = this.dataForm.specs;
    }
  }
};
</script>

<style lang="scss">
.printtemplate {
  .el-dialog {
    width: 80%;
    margin-top: 5vh !important;
    .el-dialog__body {
      max-height: 80vh !important;
    }
  }
  .note {
    width: 100%;
  }
  .w100 {
    width: 100%;
    .el-select {
      width: 100%;
    }
  }
}
</style>
